//
//  AboutAppViewController.m
//  NOAHWM
//
//  Created by Frank on 6/3/13.
//  Copyright (c) 2013 Ryan. All rights reserved.
//

#import "AboutAppViewController.h"
#import "AboutNYViewController.h"
#import "VersionViewController.h"

@interface AboutAppViewController ()

@end

@implementation AboutAppViewController

@synthesize aboutAppTableView;
@synthesize aboutAppProperties;
@synthesize adviceFeedViewController;

#pragma mark - BaseViewController methods
- (void)leftItemTapped
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setNaviTitle:@"关于App"];
    [self setLeftNaviItemWithTitle:nil imageName:@"Icon_Back"];
    [self setRightNaviItemWithTitle:nil imageName:nil];
    self.aboutAppProperties = [NSArray arrayWithObjects:@"版本信息",@"功能",@"意见反馈",nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    self.aboutAppTableView = nil;
    self.adviceFeedViewController = nil;
    self.aboutAppProperties = nil;
}

- (void)dealloc
{
    [aboutAppProperties release];
    [aboutAppTableView release];
    [adviceFeedViewController release];
    [super dealloc];
}

- (AdviceFeedbackViewController*)adviceFeedViewController{
    if (adviceFeedViewController==nil) {
        adviceFeedViewController = [[AdviceFeedbackViewController alloc]init];
    }
    return adviceFeedViewController;
}

#pragma mark - UITableViewDataSource methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.aboutAppProperties.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentify = @"cellIdentify";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if(nil == cell)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellIdentify] autorelease];
        
        UIImageView *bgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_selection@2x.png"]];
        cell.selectedBackgroundView = bgView;
        [bgView release];
        
        CGRect backImageRect = CGRectMake(10.0, 12.0, 20.0, 20.0);
        UIImageView *backImage = [[UIImageView alloc] initWithFrame:backImageRect];
        backImage.tag = 100;
        [cell.contentView addSubview:backImage];
        [backImage release];
        
        cell.accessoryView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon1_normal.png"]] autorelease];
        
        CGRect titleValueRect = CGRectMake(40.0, 2.0, 100.0, 40.0);
        UILabel *titleValue = [[UILabel alloc] initWithFrame:titleValueRect];
        titleValue.tag = 101;
        titleValue.backgroundColor = [UIColor clearColor];
        titleValue.textAlignment = UITextAlignmentLeft;
        titleValue.font = [UIFont systemFontOfSize:15];
        titleValue.adjustsFontSizeToFitWidth = YES;
        titleValue.minimumFontSize = 10;
        titleValue.textColor = [UIColor colorWithRed: 0.2 green: 0.2 blue: 0.2 alpha: 1.0];
        [cell.contentView addSubview:titleValue];
        [titleValue release];
        
        CGRect versionValueRect = CGRectMake(280.0, 2.0, 40.0, 40.0);
        UILabel *versionValue = [[UILabel alloc] initWithFrame:versionValueRect];
        versionValue.tag = 102;
        versionValue.backgroundColor = [UIColor clearColor];
        versionValue.textAlignment = UITextAlignmentCenter;
        versionValue.font = [UIFont systemFontOfSize:15];
        versionValue.adjustsFontSizeToFitWidth = YES;
        versionValue.minimumFontSize = 10;
        versionValue.textColor = [UIColor colorWithRed: 0.2 green: 0.2 blue: 0.2 alpha: 1.0];
        [cell.contentView addSubview:versionValue];
        [versionValue release];
    }
    
    NSInteger row = indexPath.row;
    if(row == 2 || row == 1)
        cell.accessoryView.hidden = NO;
    else
        cell.accessoryView.hidden = YES;
    
    UIImageView *backImage = (UIImageView *)[cell.contentView viewWithTag:100];
    UILabel *titleValue = (UILabel *)[cell.contentView viewWithTag:101];
    UILabel *versionValue = (UILabel *)[cell.contentView viewWithTag:102];

    titleValue.text = [self.aboutAppProperties objectAtIndex:indexPath.row];
    switch (indexPath.row)
    {
        case 0:
            backImage.image = [UIImage imageNamed:@"icon12_normal@2x.png"];
            versionValue.hidden = NO;
            NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString*)kCFBundleVersionKey];
            versionValue.text = version;
            break;
        case 1:
            backImage.image = [UIImage imageNamed:@"icon10_normal@2x.png"];
            versionValue.hidden = YES;
            break;
        case 2:
            backImage.image = [UIImage imageNamed:@"icon11_normal@2x.png"];
            versionValue.hidden = YES;
            break;
        default:
            break;
    }

    return cell;
}

#pragma mark - UITableViewDelegate methods
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSInteger row = indexPath.row;
    AboutNYViewController *funvc = nil;
    switch (row)
    {
        case 0:
        {
            VersionViewController *vvc = [[VersionViewController alloc] init];
            [self.navigationController pushViewController:vvc animated:YES];
            [vvc release];
        }
            break;
        case 1:
            funvc = [[AboutNYViewController alloc]init];
            [self.navigationController pushViewController:funvc animated:YES];
            [funvc release];

            
            break;
        case 2:
            [self.navigationController pushViewController:self.adviceFeedViewController animated:YES];
            break;
        case 3:
            
            break;
        case 4:
            
            break;
        default:
            break;
    }
}


@end
